package com.zx._01_基础._014_枚举;

import java.util.function.BiFunction;

// 高级特性： https://mp.weixin.qq.com/s/CxGrU9JSjvcIkDt_xDLEjg
public class SeniorDemo {

    public static void main(String[] args) {
        System.out.println(Operation.add.apply(2, 3));
        System.out.println(Operation.subtract.apply(2, 3));
        System.out.println(Operation.multiply.apply(2, 3));
    }

    public enum Operation {
        add((x, y) -> x + y),
        subtract((x, y) -> x - y),
        multiply((x, y) -> x * y);
        private final BiFunction<Integer, Integer, Integer> operation;

        private Operation(BiFunction<Integer, Integer, Integer> operation) {
            this.operation = operation;
        }

        public int apply(int x, int y) {
            return operation.apply(x, y);
        }
    }

}
